package runtime;
 
//TEst  
import java.util.List;

import com.google.gson.Gson;

import data.dynamodbfunctions.Persistence_Helper_PubForum;
import data.dynamodbfunctions.Persistence_Helper_PubThread;
import data.dynamodbfunctions.Persistence_Helper_PubEntry;
import data.exceptions.Dynamo_DB_Functions_Exception;
import data.objects.PubForum;
import data.objects.PubThread;
import data.objects.PubEntry;

public class Test {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		Gson gson = new Gson();
		
		System.out.println("Create a Forum");
				
		PubForum testforum=new PubForum("0","Alexander","Test","Testforum", "0");
		Persistence_Helper_PubForum.getInstance().create(testforum);
		PubForum testforum2=new PubForum("1","Markus","Test","Testforum2", "0");
		Persistence_Helper_PubForum.getInstance().create(testforum2);
//		testforum=new Forum("Tenant_3","Johannes",set,"Test","Testforum3");
//		forumfunctions.create(testforum);
//		testforum=new Forum("Tenant_2","Robin",set,"Test","Testforum4");
//		forumfunctions.create(testforum);

//		System.out.println("Create a Forum");
//				
//		testforum=new Forum("Tenant_1","Alex",set,"Test","Testforum");
//		forumfunctions.create(testforum);
		
		
				
		System.out.println("Create some Threads");
		
		for(int i=0;i<2;i++){
			PubThread testthread=new PubThread(testforum.getForum_id(),testforum.getTenantID(), "Alexander", "Alexander", "Das ist der Thread"+i,"Thread"+i);
			Persistence_Helper_PubThread.getInstance().create(testthread);
			for(int j=0;j<2;j++){
				PubEntry testentry=new PubEntry(testthread.getThread_id(),testthread.getTenant_id(),"Alexander","Alexander","Das ist ein Entry","Entry ("+i+","+j+")","Text("+i+","+j+")");
				Persistence_Helper_PubEntry.getInstance().create(testentry);
			}
		}

				
		System.out.println("Create some Threads");
		
		for(int i=0;i<2;i++){
			PubThread testthread2=new PubThread(testforum2.getForum_id(),testforum2.getTenantID(), "Markus", "Markus", "Das ist der Thread"+i,"Thread"+i);
			Persistence_Helper_PubThread.getInstance().create(testthread2);
			for(int j=0;j<2;j++){
				PubEntry testentry=new PubEntry(testthread2.getThread_id(),testforum2.getTenantID(),"Markus","Markus","Das ist ein Entry","Entry ("+i+","+j+")","Text("+i+","+j+")");
				Persistence_Helper_PubEntry.getInstance().create(testentry);
			}
		}

//		System.out.println("Delete Entry");
//		System.out.println(gson.toJson(entryfunctions.read("5f461584-84ca-46b4-b8a1-25e16c2a145a", "2013/05/21 11:57:00:322")));
//		System.out.println(entryfunctions.delete("5f461584-84ca-46b4-b8a1-25e16c2a145a", "2013/05/21 11:57:00:322"));
//		System.out.println(gson.toJson(entryfunctions.read("5f461584-84ca-46b4-b8a1-25e16c2a145a", "2013/05/21 11:57:00:322")));

//		
//		System.out.println("Delete Entry");
//		System.out.println(gson.toJson(entryfunctions.read("5f461584-84ca-46b4-b8a1-25e16c2a145a", "2013/05/21 11:57:00:322")));
//		System.out.println(entryfunctions.delete("5f461584-84ca-46b4-b8a1-25e16c2a145a", "2013/05/21 11:57:00:322"));
//		System.out.println(gson.toJson(entryfunctions.read("5f461584-84ca-46b4-b8a1-25e16c2a145a", "2013/05/21 11:57:00:322")));
//		
//		System.out.println("Update Entry");
//		Thread_Entry entry=entryfunctions.read("5f461584-84ca-46b4-b8a1-25e16c2a145a", "2013/05/21 11:57:00:391");
//		System.out.println(gson.toJson(entry));
//		entry.setBeschreibung("XXXXXXXXXXXXXXXXXXXXXXXXX");
//		System.out.println(entryfunctions.update(entry));
//		System.out.println(gson.toJson(entryfunctions.read("5f461584-84ca-46b4-b8a1-25e16c2a145a", "2013/05/21 11:57:00:391")));
//		
//		System.out.println("Read last Day Entrys");
//		List <Thread_Entry> entrysdays=entryfunctions.readlastXDays("6be9deac-3972-496b-80a8-3631b0914813", 0);
//		for(Thread_Entry c:entrysdays){
//			System.out.println(""+gson.toJson(c));
//		}
//		

//		System.out.println("Update Entry");
//		Thread_Entry entry=entryfunctions.read("5f461584-84ca-46b4-b8a1-25e16c2a145a", "2013/05/21 11:57:00:391");
//		System.out.println(gson.toJson(entry));
//		entry.setBeschreibung("XXXXXXXXXXXXXXXXXXXXXXXXX");
//		System.out.println(entryfunctions.update(entry));
//		System.out.println(gson.toJson(entryfunctions.read("5f461584-84ca-46b4-b8a1-25e16c2a145a", "2013/05/21 11:57:00:391")));
//		
//		System.out.println("Read last Day Entrys");
//		List <Thread_Entry> entrysdays=entryfunctions.readlastXDays("6be9deac-3972-496b-80a8-3631b0914813", 0);
//		for(Thread_Entry c:entrysdays){
//			System.out.println(""+gson.toJson(c));
//		}
		

//		System.out.println("Delete Thread");
//		System.out.println(gson.toJson(threadfunctions.read("60b66af0-c493-429a-9ecc-5176cddc16ec", "207e888f-ce25-4e42-b98f-0802ce291cfd")));
//		System.out.println(gson.toJson(threadfunctions.delete("60b66af0-c493-429a-9ecc-5176cddc16ec", "207e888f-ce25-4e42-b98f-0802ce291cfd")));
//		System.out.println(gson.toJson(threadfunctions.read("60b66af0-c493-429a-9ecc-5176cddc16ec", "207e888f-ce25-4e42-b98f-0802ce291cfd")));
//		
//		System.out.println("Update Thread");
//		Forum_Thread thread=threadfunctions.read("60b66af0-c493-429a-9ecc-5176cddc16ec", "2a345359-fb53-4b82-9f65-c29bcbb4e60e");
//		System.out.println(gson.toJson(thread));
//		thread.setBeschreibung("XXXXXXXXXXXXXXXXXXXXXXXXX");
//		System.out.println(threadfunctions.update(thread));
//		System.out.println(gson.toJson(threadfunctions.read("60b66af0-c493-429a-9ecc-5176cddc16ec", "2a345359-fb53-4b82-9f65-c29bcbb4e60e")));
//		

//		System.out.println("Read Forum");
//		System.out.println(gson.toJson(forumfunctions.read("Tenant_1", "60b66af0-c493-429a-9ecc-5176cddc16ec")));
//		
//		System.out.println("Read Forum list");
//		
//		
//		List<Forum> list=forumfunctions.readAllwithHashKey("Tenant_1");
//		System.out.println(list.toString());
//		for(Forum a:list){
//			System.out.println("Forum");
//			System.out.println(gson.toJson(a));
//			List<Forum_Thread> threads=threadfunctions.readAllwithHashKey(a.getForum_id());
//			for(Forum_Thread b:threads){
//				System.out.println("-->       "+gson.toJson(b));
//				List<Thread_Entry> entrys=entryfunctions.readAllwithHashKey(b.getThread_id());
//				for(Thread_Entry c:entrys){
//					System.out.println("--> -->       "+gson.toJson(c));
//				}
//			}
//		}

//		System.out.println("Read Forum");
//		try {
//			System.out.println(gson.toJson(forumfunctions.read("Tenant_1", "60b66af0-c493-429a-9ecc-5176cddc16ec")));
//		} catch (Dynamo_DB_Functions_Exception e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
		
		System.out.println("Read Forum list");
		
		
		List<PubForum> list=null;
		try {
			list = Persistence_Helper_PubForum.getInstance().readAllwithHashKey("0");
		} catch (Dynamo_DB_Functions_Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println(list.toString());
		for(PubForum a:list){
			System.out.println("Forum");
			System.out.println(gson.toJson(a));
			List<PubThread> threads=null;
			try {
				threads = Persistence_Helper_PubThread.getInstance().readAllwithHashKey(a.getForum_id());
			} catch (Dynamo_DB_Functions_Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			for(PubThread b:threads){
				System.out.println("-->       "+gson.toJson(b));
				List<PubEntry> entrys=null;
				try {
					entrys = Persistence_Helper_PubEntry.getInstance().readAllwithHashKey(b.getThread_id());
				} catch (Dynamo_DB_Functions_Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				for(PubEntry c:entrys){
					System.out.println("--> -->       "+gson.toJson(c));
				}
			}
		}

//		System.out.println("Update Forum");
//		
//		testforum.setBeschreibung("XXXXXXXXXXXXXXXXXXXXXXXX");
//		forumfunctions.update(testforum);
//		
//		System.out.println("Delete Forum");
//		System.out.println(gson.toJson(forumfunctions.delete("Tenant_1","68464602-4ffd-414f-b00b-f28fd09befc1")));
//	
//		System.out.println("Read All");
//		
//		
		List<PubForum> list2=null;
		try {
			list2 = Persistence_Helper_PubForum.getInstance().readAllwithHashKey("1");
		} catch (Dynamo_DB_Functions_Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		for(PubForum a:list2){
			System.out.println(gson.toJson(a));
			List<PubThread> threads=null;
			try {
				threads = Persistence_Helper_PubThread.getInstance().readAllwithHashKey(a.getForum_id());
			} catch (Dynamo_DB_Functions_Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			for(PubThread b:threads){
				System.out.println("-->       "+gson.toJson(b));
				List<PubEntry> entrys=null;
				try {
					entrys = Persistence_Helper_PubEntry.getInstance().readAllwithHashKey(b.getThread_id());
				} catch (Dynamo_DB_Functions_Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				for(PubEntry c:entrys){
					System.out.println("--> -->       "+gson.toJson(c));
				}
			}
		}
	System.out.println("Ende");	
	}

}
